package com.ctgu.rabbitmq.rabbitmq.queue.maxLength;

import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @ ClassName MaxLengthConsumer
 * @ Author Alex2
 * @ Date 2025/8/15 10:24
 **/
@Log4j2
@Component
public class MaxLengthConsumer {

    private static final String TAG = "Alex";

    // 普通队列消费者
    @RabbitListener(queues = MaxLengthConfig.NORMAL_QUEUE_MAX, ackMode = "MANUAL")
    public void consumeNormal(Message message, Channel channel) throws IOException {
        String body = new String(message.getBody());
        log.debug("{} : 普通队列收到消息 : {}", TAG, body);
        // 不立即 ack，让消息堆积，模拟测试时关闭注释，模拟测试完成后打开注释
        // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

    // 死信队列消费者
    @RabbitListener(queues = MaxLengthConfig.DLX_QUEUE_MAX)
    public void consumeDLX(String message) {
        log.debug("{} : 死信队列收到消息 : {}", TAG, message);
    }
}